package com.okilo.online.app.apt

import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import com.okilo.online.app.R
import com.okilo.online.app.databinding.OkiloActPermListChildItemBinding
import com.okilo.online.app.tools.apt.OkiloRecyclerViewAdapter
import com.okilo.online.app.tools.apt.OkiloViewHolderHelper
import org.json.JSONObject

/**
 * OkiloLoan
 * @Author wwdeng
 * @CreateTime: 2024/11/19 10:43
 * @Annotation：订单列表适配器
 */
class OkiloPermApt(recyclerView: RecyclerView?) : OkiloRecyclerViewAdapter<JSONObject>(recyclerView,
    R.layout.okilo_act_perm_list_item) {

    override fun fillData(helper: OkiloViewHolderHelper, position: Int, model: JSONObject) {
        val okiloPermIcon = helper.getImageView(R.id.okiloPermIcon)
        okiloPermIcon.setImageResource(model.optInt("icon"))

        helper.setText(R.id.okiloPermTitle, model.optString("title"))

        val okiloPermChild = helper.getView<LinearLayout>(R.id.okiloPermChild)
        okiloPermChild.removeAllViews()
        val itemList = model.optJSONArray("msgList")
        itemList?.let {
            for (i in 0..< itemList.length()){
                val item = itemList.optJSONObject(i)
                val itemView = OkiloActPermListChildItemBinding.inflate(LayoutInflater.from(mContext))
                val showTitle = item.optString("title")
                if (showTitle.isNotEmpty()){
                    itemView.okiloPermChildTitle.text = showTitle
                    itemView.okiloPermChildTitle.visibility = View.VISIBLE
                } else {
                    itemView.okiloPermChildTitle.visibility = View.GONE
                }
                itemView.okiloPermChildReason.text = item.optString("des")
                okiloPermChild.addView(itemView.root)
            }
        }
    }
}